<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl"/>

    <script>
        $(function () {
            //弹出模态框
            $(".inputBtn").click(function () {

                //清除模态框的数据
                $("#inputModal").clearForm();
              var json = $(this).data("json");
                //console.log(json);
                if (json){
                   $("#editForm input[name='id']").val(json.id);
                   $("#editForm input[name='title']").val(json.title);
                   $("#editForm input[name='subTitle']").val(json.subTitle);
                   $("#editForm input[name='coverUrl']").val(json.coverUrl);
                   $("#editForm select[name='state']").val(json.state);
                   $("#editForm select[name='place.id']").val(json.placeId);
               }

                $("#inputModal").modal("show");
            });
            //在模态框里面提交表单
            $("#save").click(function () {
                $("#editForm").ajaxSubmit();
            })
        })


    </script>

</head>
<body>

<!-- 模态框（Modal） -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategy/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="#" width="60px">
                            <input type="hidden" class="form-control" name="coverUrl">
                            <input type="file" class="form-control" name="pic">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属地区：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="place.id">
                                <option value="-1">全部地区</option>
                                 <#list places as p>   <#--这个要查出来-->
                                     <option value="${p.id}">${p.name}</option>
                                 </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="-1">---请选择---</option>
                                <option value="1">正常</option>
                                <option value="2">推荐</option>
                                <option value="3">禁用</option>
                            </select>
                            <#--<script>
                                    $("#editForm select[name='state']").val(${qo.state});
                            </script>-->
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-save" id="save">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#assign menu="strategy"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大攻略管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <button id="btn_add" type="button" class="btn btn-success">
                    <span class="glyphicon glyphicon-plus inputBtn"></span> 添加
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>封面</th>
                    <th>攻略标题</th>
                    <th>副标题</th>
                    <th>所属地区</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>><img src="${(entity.coverUrl)!}" width="30px"></td>
                        <td>${(entity.title)!}</td>
                        <td>${(entity.subTitle)!}</td>
                        <td>${(entity.place.name)!}</td>
                        <td>${(entity.stateDisplay)!}</td>
                        <td><a href="javascript:;" class="inputBtn" data-json='${entity.jsonString}'>修改</a></td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


</body>
</html>